-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix matching codecs with different rate or channels #3021
base: master
Are you sure you want to change the base?
Conversation
a488626
to
0e8d4ec
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3021 +/- ##
==========================================
+ Coverage 78.22% 78.25% +0.02%
==========================================
Files 91 91
Lines 11159 11234 +75
==========================================
+ Hits 8729 8791 +62
- Misses 1940 1950 +10
- Partials 490 493 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
54a37a9
to
eb71ae1
Compare
eb71ae1
to
55b280c
Compare
c10ed6e
to
b31dde1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for this! Just few random thoughts; although I'm not fully confident with the Pion codebase yet to approve this so you'll have to wait for @Sean-Der , this change does make sense to me.
Thank you again <3
@JoeTurki thank you very much for the detailed review. I'm gonna rewrite this in order to provide defaults for every supported codec and support any existing situation, and at the same time solve the original issue that led to this PR (that was the fact that LPCM/48000/2 was wrongfully associated with LPCM/44100/1, leading to corrupted audio). |
4ef7239
to
aa27913
Compare
Thanks for this pr! I just tested this branch together with livekit-go-sdk v2.4.2 inside MediaMTX v1.11.3 and it works great 👍 (It solves a problem we were seeing where Livekit was not accepting streams when compiled with the MediaMTX fork of pion/webrtc) |
@aler9 Thank you so much <3 |
28ba39d
to
e5cb963
Compare
Consider clock rate and channels when matching codecs. This allows to support codecs with the same MIME type but sample rate or channel count that might be different from the default ones, like PCMU, PCMA, LPCM and multiopus.
e5cb963
to
8eda30b
Compare
Description
In pion/webrtc, currently codecs are matched regardless of the clock rate and the channel count, and this makes impossible to fully support codecs that might have a clock rate or channel count different than the default one, in particular LPCM, PCMU, PCMA and multiopus (the last one is a custom Opus variant present in the Chrome source code to support multichannel Opus).
For instance, let's suppose a peer (receiver) wants to receive an audio track encoded with LPCM, 48khz sample rate and 2 channels. This receiver doesn't know the audio codec yet, therefore it advertises all supported sample rates in the SDP:
The other peer (sender) receives the SDP, but since the clock rate and channel count are not taken into consideration when matching codecs, the sender codec
LPCM/48000/2
is wrongly associated with the receiver codecLPCM/44100
. The result is that the audio track cannot be decoded correctly from the receiver side.This patch fixes the issue and has been running smoothly in MediaMTX for almost a year.
Unfortunately, in lots of examples and tests, clock rate and/or channels are not present (and in fact they are producing horrible SDPs that contain
VP8/0
instead ofVP8/90000
and are incompatible with lots of servers) therefore this new check causes troubles in existing code. In order to maintain compatibility, default clock rates and channels are provided for most codecs.In the future, it might be better to update examples (i can do it in a future patch) and remove the exception.